package com.milloc.db.wrapper;

import com.milloc.db.bo.ScriptBO;
import com.milloc.db.entity.SQLEntity;
import com.milloc.db.entity.ScriptEntity;
import com.milloc.db.service.SQLRunnerService;
import com.milloc.db.service.SQLService;
import com.milloc.db.service.ScriptService;
import lombok.AllArgsConstructor;

import java.util.Map;

/**
 * @author gongdeming
 * @create 2019-08-27
 */
@AllArgsConstructor
public class RunnerWrapper {
    private SQLRunnerService sqlRunnerService;
    private ScriptBO scriptBO;
    private SQLService sqlService;
    private ScriptService scriptService;

    public Object query(String sqlId, Map<String, Object> params) {
        SQLEntity sqlEntity = sqlService.fetchOne(sqlId);
        return sqlRunnerService.runSQL(sqlEntity, params);
    }

    public Object run(String scriptId, Map<String, Object> params) {
        ScriptEntity scriptEntity = scriptService.fetchOne(scriptId);
        return scriptBO.run(scriptEntity, params);
    }
}
